package com.housesales.web;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import module.Logs;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import utils.PageUtil;
import bussinessService.basicbussinessService;
import bussinessService.impl.LogsBussinessServiceImpl;
import domain.vo.JSONObject;
import domain.vo.LogVO;
import domain.vo.LogsQueryObject;

/**
 * 
* @ClassName: LogsController 
* @Description: logs MVC
* @author chenchao
* @date 2014年1月20日 下午3:43:52 
*
 */
@Controller
@RequestMapping("/logs")
public class LogsController {
	private Logger logger = Logger.getLogger(LogsController.class.getName());
	/**
	 * 日志业务层
	 */
	private basicbussinessService<Logs, LogVO> logBIS = new LogsBussinessServiceImpl();
	
	@RequestMapping("/viewLogsJson")
	public @ResponseBody
	JSONObject<LogVO> viewListJson(
			@RequestParam("page") int page, @RequestParam("rows") int rows,LogsQueryObject queryObject,HttpServletRequest request) {
		JSONObject<LogVO> json = new JSONObject<LogVO>();
		List<LogVO> vos = new ArrayList<LogVO>();
		try {
			PageUtil.Page(page, rows);
			queryObject.setStart(PageUtil.start);
			queryObject.setEnd(PageUtil.end);
			queryObject.setFkid(request.getParameter("fkid"));
			queryObject.setModule(request.getParameter("module"));
			int len = logBIS.countByQueryObject(queryObject);
			vos = logBIS.getObjectByQueryObject(queryObject);
			json.setTotal(len);
			json.setRows(vos);
		} catch (SQLException e) {
			logger.error(e.getMessage());
		}

		return json;

	}
}
